const methods = {
  group(array, subGroupLength) {
      let index = 0;
      let newArray = [];
      while(index < array.length) {
        newArray.push(array.slice(index, index += subGroupLength));
      }
      return newArray;
  },
  /*
  * 格式化时间戳
  */
  formatDate(time, number) {
    let date = new Date(time) // 如果time是13位, 则不需要乘1000
    let Y = date.getFullYear() + "-"
    let M = ((date.getMonth() + 1) < 10) ? ("0" + (date.getMonth() + 1) + "-") : ((date.getMonth() + 1) + "-")
    let D = ((date.getDay() < 10) ? ("0" + date.getDay()) : date.getDay()) + " "
    let h = ((date.getHours() < 10) ? ("0" + date.getHours()) : date.getHours()) + ":"
    let m = ((date.getMinutes() < 10) ? ("0" + date.getMinutes()) : date.getMinutes()) + ":"
    let s = (date.getSeconds() < 10) ? ("0" + date.getSeconds()) : date.getSeconds()
    switch (number) {
      case 3:
        return h+m+s;
      case 6:
        return Y+M+D+h+m+s
      default:
        return Y+M+D
    }
  },
  // s 转换为 时分秒
  secondsFormat(s) {
    var day = Math.floor(s / (24 * 3600)); // Math.floor()向下取整
    var hour = Math.floor((s - day * 24 * 3600) / 3600);
    var minute = Math.floor((s - day * 24 * 3600 - hour * 3600) / 60);
    var second = s - day * 24 * 3600 - hour * 3600 - minute * 60;
    if (hour) {
      return hour + ":" + minute + ":" + second;
    } else {
      if (second < 10) {
        if (minute < 10) {
          return "0" + minute + ":" + second + "0";
        } else {
          return minute + ":" + second + "0";
        }
      } else {
        return minute + ":" + second;
      }
    }
  },
  // 秒 转换为 分秒
  secondsFormat2(s) {
    s =  Math.floor(s / 1000);
    let minute = Math.floor(s / 60);
    let second = s - minute * 60;

    return  minute.toString().padStart(2, '0') + ":" + second.toString().padStart(2, '0');
    
  }
} 
export default methods;